<?php
class sys_sinaController extends Controller
{
	var $widKey = false;

    public function actionIndex()
	{		     
        $this->render('login');
        Yii::app()->getSession()->closeSession();
		Yii::app()->getSession()->destroy();
	}	
	public function actionSystem()
	{		
		if(isset(Yii::app()->session['login']))
			$this->render('index');
		else{
			$host  = $_SERVER['HTTP_HOST'];
			$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
			$extra = 'index.php';
			header("Location: http://$host$uri/$extra");
			exit;
		}
	}
	public function actionLogin()
	{
		$model = t_usuario::model()->find("usulogin=:keyUser AND usupass=:keyPass", 
			array(
				':keyUser' => $_REQUEST['user'], 
				':keyPass' => $_REQUEST['pass']
			)
			);
        if(is_object($model)){
            if($model['usuestado'] == 'ACTIVO'){
            	Yii::app()->session->sessionID;
                Yii::app()->session['login'] = $model->usulogin;
                Yii::app()->request->cookies['userLogin'] = new CHttpCookie('userLogin', $model->usulogin);
            	echo true;
            }
            else
            	echo "El usuario no se ecuentra Activo.";
        }
        else
        	echo "El usuario o contraseña no coinciden.";
	}
}